<?php
/**
 * $Id: default.php 10571 2008-07-21 01:27:35Z pasamio $
 */
defined( '_JEXEC' ) or die( 'Restricted access' );
$baseurl = JURI::base();
$product_image_url = $baseurl.'/images/products'; 
?>
<div id="productContainer">
	<?php if($this->product->image): ?>
	<div class="Image">
		<img src="<?php echo $product_image_url.'/'.$this->product->image ?>" alt="<?php echo $this->product->title ?>" />
	</div>	
	<?php endif; ?>
	<div id="productInfo">
		<!--h2><?php echo $this->product->title ?></h2-->
		<ul>
			<li><span><?php echo JText::_('Details') ?>:</span><?php echo $this->product->description ?></li>
			<li><span><?php echo JText::_('Cost') ?>:</span><?php echo ProductHelper::renderPrice($this->product->price) ?></li>
			<?php if($this->product->type): ?>
			<li><span><?php echo JText::_('Size') ?>:</span><?php echo ProductHelper::renderSize() ?></li>
			<?php endif; ?>
			<li><span><?php echo JText::_('Quantity') ?>:</span><input type="text" name="quantity" id="quantity" /> </li>
			<li><hr /></li>
			<li><div class="AddToCard"><a id="cartAdd" href="javascript: void(0);" title="<?php echo JText::_('Add to cart') ?>"><?php echo JText::_('Add to cart') ?></a></div></li>
		</ul>
	</div>
</div>
<div class="Clear"></div>
<script>
// execute your scripts when DOM is ready. this is a good habit
$(function() {		
	jQuery("#cartAdd").click(
		function(){
			jQuery("msg").css('display', 'none');
			var ok = 1;
			if(jQuery("#quantity").val() == "" || !/^\d+$/.test(jQuery("#quantity").val())){
				jQuery('<div class="quick-alert"><?php echo JText::_('Please input a valid quantity!') ?></div>')
							 .insertAfter( jQuery("#quantity") )
							 .fadeIn('slow')
							 .animate({opacity: 1.0}, 3000)
							 .fadeOut('slow', function() {
							   $(this).remove();
							 });
				jQuery("#quantity").css('border', 'red solid 1px');			 
				ok = 0;			 
			}else{
				jQuery("#quantity").css('border', '#7f9db9 solid 1px');
			}
			if(ok == 1){
				jQuery.post("index.php", { option:'com_products', task:'add2cart', id: "<?php echo $this->product->id ?>", qty: jQuery("#quantity").val(), title: '<?php echo $this->product->title ?>'<?php if($this->product->type): ?>, size: jQuery("#ring_size").val()<?php endif; ?>, img: '<?php echo $this->product->image ?>' },
					function(data){
				    	if(data.msg == 'added'){
				    		jQuery('<div class="quick-msg"><?php echo JText::_('Add product to cart sucessfully!') ?></div>')
								 .insertAfter( jQuery("#quantity") )
								 .fadeIn('slow')
								 .animate({opacity: 1.0}, 3000)
								 .fadeOut('slow', function() {
								   $(this).remove();
								 });
							jQuery("#cartForm").html(data.cart);
							jQuery("#numberItems").html('  ('+data.numberItems+')');	 
				    	}else if(data.msg == 'fail'){
				    		jQuery('<div class="quick-alert"><?php echo JText::_('Fail to add product to cart!') ?></div>')
								 .insertAfter( jQuery("#quantity") )
								 .fadeIn('slow')
								 .animate({opacity: 1.0}, 3000)
								 .fadeOut('slow', function() {
								   $(this).remove();
								 });
				    	}
					}, "json"
				);
			}
		}
	);
});
</script>

